package cn.wizzer.app.code.commons.builder;

import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLClassLoader;

public class Test {

    public static void main(String[] args) throws MalformedURLException, ClassNotFoundException {
//        File programRootDir = new File("target/classes/");
//        //URLClassLoader classLoader = (URLClassLoader) ClassLoader.getSystemClassLoader();
//        //URL newurl = new URL(programRootDir.getPath());
//
//        URLClassLoader classLoader = (URLClassLoader) ClassLoader.getSystemClassLoader();
//        //URLClassLoader classLoader = new URLClassLoader(new URL[]{newurl},ClassLoader.getSystemClassLoader());
//
//        System.out.println(classLoader.getURLs());

        // 获取系统类加载器
        ClassLoader systemClassLoader = ClassLoader.getSystemClassLoader();
        System.out.println(systemClassLoader);
        URLClassLoader urlclassloder = (URLClassLoader) systemClassLoader.getParent();
        System.out.println("urlclassloder:"+urlclassloder.toString());
        // 获取系统类加载器的父类加载器 --> 扩展类加载器
        ClassLoader parent = systemClassLoader.getParent();
        System.out.println(parent);
        // 获取扩展类加载器的父类加载器 --> 根加载器（C/C++）
        ClassLoader parent1 = parent.getParent();
        System.out.println(parent1);
        // 测试当前类的加载器
        ClassLoader classLoader = Class.forName("cn.wizzer.app.code.commons.builder.Test").getClassLoader();
        System.out.println(classLoader);
        // 测试JDK内置的类加载器
        classLoader = Class.forName("java.lang.Object").getClassLoader();
        System.out.println(classLoader);
        // 如何获得系统类加载器可以加载的路径
        System.out.println(System.getProperty("java.class.path"));
    }
}
